package com.ouc.eddyAlgorithm.controller;

import com.ouc.common.annotation.Log;
import com.ouc.common.core.controller.BaseController;
import com.ouc.common.core.domain.AjaxResult;
import com.ouc.common.core.page.TableDataInfo;
import com.ouc.common.enums.BusinessType;
import com.ouc.common.utils.poi.ExcelUtil;
import com.ouc.eddyAlgorithm.entity.EddySet;
import com.ouc.eddyAlgorithm.service.EddyAlgorithmSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;

import java.util.List;
import org.springframework.web.bind.annotation.*;

/**
 * eddySet的控制层
 *
 * @author B504
 */

@Controller
@CrossOrigin
@RequestMapping("/system/eddyset")
public class EddySetController extends BaseController {

  @Autowired
  EddyAlgorithmSetService eddyAlgorithmSetService;

  private String prefix = "dataManage/eddy";

//  @RequiresPermissions("system:eddy:view")
  @GetMapping()
  public String eddySet() {
    return prefix + "/eddyset";
  }

  /**
   * 查询eddyset列表
   */
//  @RequiresPermissions("system:eddySet:list")
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(EddySet eddySet) {
    startPage();
    List<EddySet> list = eddyAlgorithmSetService.selectEddySet(eddySet);
    return getDataTable(list);
  }

  /**
   * 导出eddyset列表
   */
//  @RequiresPermissions("system:eddySet:export")
  @Log(title = "eddySet", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(EddySet eddySet) {
    List<EddySet> list = eddyAlgorithmSetService.selectEddySet(eddySet);
    ExcelUtil<EddySet> util = new ExcelUtil<>(EddySet.class);
    return util.exportExcel(list, "eddySet临时数据表");
  }

  /**
   * 新增eddyset
   */
  @GetMapping("/add")
  public String add() {
    return prefix + "/add";
  }

  /**
   * 新增保存eddyset
   */
//  @RequiresPermissions("system:eddySet:add")
  @Log(title = "eddySet", businessType = BusinessType.INSERT)
  @PostMapping("/add")
  @ResponseBody
  public AjaxResult addSave(EddySet eddySet) {
    return toAjax(eddyAlgorithmSetService.insertEddySet(eddySet));
  }

  /**
   * 修改eddyset
   */
//  @RequiresPermissions("system:eddySet:edit")
  @GetMapping("/edit/{id}")
  public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
    EddySet eddySet = eddyAlgorithmSetService.selectEddySetById(id);
    mmap.put("eddySet", eddySet);
    return prefix + "/edit";
  }

  /**
   * 修改保存eddyset
   */
//  @RequiresPermissions("system:eddySet:edit")
  @Log(title = "eddySet", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  @ResponseBody
  public AjaxResult editSave(EddySet eddySet) {
    return toAjax(eddyAlgorithmSetService.updateEddySet(eddySet));
  }

  /**
   * 删除eddyset
   */
//  @RequiresPermissions("system:eddySet:remove")
  @Log(title = "eddySet", businessType = BusinessType.DELETE)
  @PostMapping("/remove")
  @ResponseBody
  public AjaxResult remove(Integer ids) {
    return toAjax(eddyAlgorithmSetService.deleteEddySetById(ids));
  }

  /**
   * 清空表
   *
   * @return
   */
  @Log(title = "eddySet", businessType = BusinessType.CLEAN)
  @RequestMapping("/cleanAll")
  @ResponseBody
  public AjaxResult cleanAll() {
    eddyAlgorithmSetService.truncateTable();
    return AjaxResult.success("成功清空数据");
  }


  /**
   * 获取txt中读取的涡旋信息
   *
   * @return
   */
  @Log(title = "eddySet", businessType = BusinessType.EXPORT)
  @RequestMapping("/getEddyFormTxt")
  @ResponseBody
  public AjaxResult getEddyFormTxt() {
    List<EddySet> eddyFormTxt = eddyAlgorithmSetService.getEddyFormTxt("C:\\Users\\B504\\Desktop\\三维可视化\\20220101全球总.txt");
    return AjaxResult.success(eddyFormTxt);
  }

}
